package com.huike.web.controller.report;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.huike.common.core.domain.AjaxResult;
import com.huike.report.service.IReportService;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

@RestController
@RequestMapping("/index")
public class IndexController {

    @Autowired
    private IReportService reportService;


    /**
     * 首页--基础数据统计
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/getBaseInfo")
    public AjaxResult getBaseInfo(@RequestParam("beginCreateTime") String beginCreateTime,
                                  @RequestParam("endCreateTime") String endCreateTime){
        return AjaxResult.success(reportService.getBaseInfo(beginCreateTime,endCreateTime));
    }

    /**
     * 首页—今天基础数据
     * URL:GET： http://localhost/api/index/getTodayInfo
     * 入参：无
     * 出参：indexTodayInfoVo
     */
    @GetMapping("getTodayInfo")
    public AjaxResult getTodayInfo(){
        Date beginTime = new Date();
        //当前时间
        Calendar calendar = new GregorianCalendar();
        //设置当前时间
        calendar.setTime(beginTime);
        //计算时间
        calendar.add(Calendar.DATE,0);
        //获取结束时间
        Date endTime = calendar.getTime();
        //设置日期的格式
        SimpleDateFormat sim = new SimpleDateFormat("y-M-d");
        String beginCreateTime = sim.format(beginTime);
        String endCreateTime = sim.format(endTime);
        return AjaxResult.success(reportService.getTodayInfo(beginCreateTime,endCreateTime));
    }


    /**
     * 首页-今日待办事务
     * URL：http://localhost/api/index/getTodoInfo?beginCreateTime=2022-10-05&endCreateTime=2022-11-04
     * 请求方法: GET
     * @param beginCreateTime  开始时间
     * @param endCreateTime    结束时间
     * @return
     */
    @GetMapping("/getTodoInfo")
    public AjaxResult getTodoInfo(@RequestParam("beginCreateTime") String beginCreateTime,
                                  @RequestParam("endCreateTime") String endCreateTime){
        return AjaxResult.success(reportService.getIndexTodoInfoVo(beginCreateTime,endCreateTime));
    }


    /**
     * 首页-商机龙虎榜
     * URL:GET http://localhost/api/index/businessChangeStatistics?beginCreateTime=2022-08-28&endCreateTime=2022-09-27
     * 入参：beginCreateTime：endCreateTime
     * 出参：ChangeStatistics 集合
     */
    @GetMapping("/businessChangeStatistics")
    public AjaxResult getBusinessChangeStatistics(@RequestParam("beginCreateTime") String beginCreateTime,
                                                  @RequestParam("endCreateTime") String endCreateTime){
        return AjaxResult.success(reportService.getBusinessChangeStatistics(beginCreateTime, endCreateTime));
    }

    /**
     * URL:GET http://localhost/api/index/salesStatistic?beginCreateTime=2022-08-30&endCreateTime=2022-09-29
     * 入参：beginCreateTime：endCreateTime
     * 出参：ChangeStatistics 集合
     */
    @GetMapping("/salesStatistic")
    public AjaxResult getClueChangeStatistics(@RequestParam("beginCreateTime") String beginCreateTime,
                                              @RequestParam("endCreateTime") String endCreateTime){
        return AjaxResult.success(reportService.getClueChangeStatistics(beginCreateTime, endCreateTime));
    }
}